
LoginPanel = {};
local this = LoginPanel;

local transform;
local gameObject;
local behaviour;

function LoginPanel.New()
    panelMgr:CreatePanel("Login",nil);
end

function LoginPanel.Awake(obj)
    gameObject=obj;
    transform=obj.transform;
    behaviour = transform:GetComponent('LuaBehaviour');

    this.loginBtn = transform:Find("LoginBtn").gameObject;
    this.inputfield = transform:Find("InputField"):GetComponent('UIInput');
    --显示上次输入名字
    this.inputfield.value = PlayerPrefs.GetString("INPUT_USERID");

    behaviour:AddClick(this.loginBtn,this.OnLoginClick)
end

function LoginPanel.OnLoginClick()
    local userid = this.inputfield.value;
    --缓存登录名称
    PlayerPrefs.SetString("INPUT_USERID",userid);

    --构造pb实体类
    local p = {username = userid };
    local code = protobuf.encode("lin.User", p)

    --封装bytebuffer，发送
    local buffer = ByteBuffer.New();
    buffer:WriteShort(Protocal.ReqLogin);--登录状态
    buffer:WriteBuffer(code);
    networkMgr:SendMessage(buffer);
end